function keyPressed(event) {
	var box = $("box");
	$("box").style.backgroundColor = "red";
	if(event.keyCode == Event.KEY_LEFT) {
		box.style.left = parseInt(Element.getStyle(box, "left")) - 10 + "px";
	} else if(event.keyCode == Event.KEY_RIGHT) {
		box.style.left = parseInt(Element.getStyle(box, "left")) + 10 + "px";
	} else if(event.keyCode == Event.KEY_DOWN) {
		box.style.top = parseInt(Element.getStyle(box, "top")) + 10 + "px";
	} else if(event.keyCode == Event.KEY_UP) {
		box.style.top = parseInt(Element.getStyle(box, "top")) - 10 + "px";
	}
}

function updateBox() {
	makeJSONRequest();
     //console.log('update box ' + number);
}

function makeJSONRequest() {

   var currentTime = new Date()
	var month = currentTime.getTime();

  var params = {};
  params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
  var url = "http://uwthetaxi.com/ghang/will/id1?t=" + month;
  gadgets.io.makeRequest(url, response, params);
  
};

function response(obj) {
	var currentTime = new Date()
	var month = currentTime.getTime();
	var box = $("box");

  var data = obj.data;
  if(data == 100) {
  	//console.log("gas ON");
  	//box.style.backgroundColor = "red";
  	oPlayer.speedinc = 1;
  } else if(data == -100) {
  	//console.log("gas OFF");
  	//box.style.backgroundColor = "blue";
  	oPlayer.speedinc -= 0.2;
  } else {
  	if (data == null)
  		data = 0;
  	if(data <= -2){ 
  		oPlayer.rotincdir = 1;
  	}else if(data >= 2) {
  		oPlayer.rotincdir = -1;
  	}
  	//	box.style.left = data * 5 + "px";
    //console.log(data);
  }
};

// A function to be run at app initialization time which registers our callbacks
function init() {
  console.log('Init app.');

  var apiReady = function(eventObj) {
    if (eventObj.isApiReady) {
      console.log('API is ready');
	  gapi.hangout.onApiReady.remove(apiReady);
	  
	  console.log('start timer');
	  setInterval(updateBox, 200);
    }
  };

  // This application is pretty simple, but use this special api ready state
  // event if you would like to any more complex app setup.
  gapi.hangout.onApiReady.add(apiReady);  
  
  Event.observe(document, 'keydown', keyPressed);
}

gadgets.util.registerOnLoadHandler(init);